﻿using System;
using System.Security;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Pixster
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Authentication", 
                "Account/{action}",
                new {controller = "Account", action = ""});

            routes.MapRoute(
                "Administration", 
                "Admin/{action}",
                new {controller = "Admin", action = ""});

            routes.MapRoute(
                "GetPhoto",
                "Album/GetPhoto/{directory}/{albumName}/{photoName}",
                new { controller = "Album", action = "GetPhoto", directory = "", albumName = "", photoName = "" });

            routes.MapRoute(
                "Albums", 
                "Album/{directory}/{albumName}",
                new {controller = "Album", action = "Index", directory = "", albumName = ""});

            routes.MapRoute(
                "Directories", 
                "Directory/{directory}",
                new {controller = "Directory", action = "Index", directory = ""});

            routes.MapRoute(
                "Photos3",
                "Photo/Index3/",
                new { controller = "Photo", action = "Index3" });

            routes.MapRoute(
                "Photos2",
                "Photo/Index2/",
                new { controller = "Photo", action = "Index2" });

            routes.MapRoute(
                "Photos", 
                "Photo/{directory}/{albumName}/{photoName}",
                new {controller = "Photo", action = "Index", directory = "", albumName = "", photoName = ""});

            //routes.MapRoute("Default", "{*path}", new {controller = "Home", action = "Index"});

            routes.MapRoute(
                "Default", 
                "{controller}/{action}/{id}", 
                new { controller = "Home", action = "Index", id = "" } );
        }

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }

        protected void Application_Error(object sender, EventArgs e)
        {
            var ex = Server.GetLastError().GetBaseException();
            if (ex is SecurityException)
            {
                Response.Redirect("/Account/LogOn");
            }
        }
    }
}